public class test526_2 {
    public static void main(String[] args) {
        //**************数组的扩容
        int[] arr1 = {1,2,3,4};
        /*在arr1中新增加三位元素10,23,56*/
        int[] newArr1 = new int [arr1.length << 1];
        for (int i = 0; i < arr1.length; i++) {
            newArr1[i] = arr1[i];
        }
        newArr1[arr1.length] = 10;

        newArr1[arr1.length + 1] = 23;

        newArr1[arr1.length + 2] = 56;

        arr1 = newArr1;
        //遍历
        for (int i = 0; i < newArr1.length; i++) {
            System.out.print(arr1[i] + "\t");
        }
        //************数组的缩容
        /*题目：现有数组 int[] arr={1,2,3,4,5,6,7}。现需删除数组中索引为 4 的元素。*/
        System.out.println();
        int[] arr2 = {1,2,3,4,5,6,7};
        int delIndex = 4;
        for (int i = delIndex; i < arr2.length - 1; i++) {
            arr2[i] = arr2[i + 1];
        }
        arr2[arr2.length - 1] = 0;
        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i] + "\t");
        }
    }
}
